/*
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

package com.facebook.animation.drawable.animator;

import com.facebook.fresco.animation.drawable.AnimatedDrawable2;
import com.facebook.fresco.animation.drawable.animator.AnimatedDrawable2ValueAnimatorHelper;
import com.facebook.imagepipeline.annotation.Nullable;
import ohos.agp.animation.AnimatorValue;
import ohos.agp.components.element.Element;

/**
 * Helper class to create {@link AnimatorValue}s for animated drawables. Currently, this class only
 * supports API 11 (Honeycomb) and above.
 *
 * <p>Supported drawable types: - {@link AnimatedDrawable2}
 */
public class AnimatedDrawableValueAnimatorHelper {

  /**
   * Create a value animator for the given animation drawable and max animation duration in ms.
   *
   * @param drawable the drawable to create the animator for
   * @param maxDurationMs the max duration in ms
   * @return the animator to use
   */
  @Nullable
  public static AnimatorValue createValueAnimator(Element drawable, int maxDurationMs) {

    if (drawable instanceof AnimatedDrawable2) {
      return AnimatedDrawable2ValueAnimatorHelper.createValueAnimator(
          (AnimatedDrawable2) drawable, maxDurationMs);
    }
    return null;
  }

  /**
   * Create a value animator for the given animation drawable.
   *
   * @param drawable the drawable to create the animator for
   * @return the animator to use
   */
  @Nullable
  public static AnimatorValue createValueAnimator(Element drawable) {

    if (drawable instanceof AnimatedDrawable2) {
      return AnimatedDrawable2ValueAnimatorHelper.createValueAnimator((AnimatedDrawable2) drawable);
    }
    return null;
  }

  /**
   * Create an animator update listener to be used to update the drawable to be animated.
   *
   * @param drawable the drawable to create the animator update listener for
   * @return the listener to use
   */
  @Nullable
  public static AnimatorValue.ValueUpdateListener createAnimatorUpdateListener(
      final Element drawable) {
    if (drawable instanceof AnimatedDrawable2) {
      return AnimatedDrawable2ValueAnimatorHelper.createAnimatorUpdateListener(
          (AnimatedDrawable2) drawable);
    }
    return null;
  }

  private AnimatedDrawableValueAnimatorHelper() {}
}
